//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import http from '../../api/http'
import axios from 'axios'
let extension = {
    components: {
      //动态扩充组件或组件路径
      //表单header、content、footer对应位置扩充的组件
      gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
      gridBody: "",
      gridFooter: "",
      //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
      modelHeader: "",
      modelBody: "",
      modelFooter: ""
    },
    buttons: { view: [], box: [], detail: [] }, //扩展的按钮
    methods: {
      //事件扩展
      onInit() {
        let channel_type = this.getFormOption('channel_type')
        let params = {
            order: "desc",
            page: 1,
            rows: 30000,
            sort: "createDate",
        }
        this.http.post('/api/Channels/getPageData',params).then(res => {
            channel_type.data = []
            channel_type.data = res.rows.map(i => {
                return {
                    key: i.distributorCode,
                    value: i.distributorName
                }
            })
            channel_type.data.unshift({
                key: 'erp',
                value: '窗口柜台'
            })
        })
        this.searchFormFileds.date_time=[this.getStartDate() ,this.getEndDate()]
      },
      getFormOption (field) {
        let option;
        this.searchFormOptions.forEach(x => {
          x.forEach(item => {
            if (item.field == field) {
              option = item;
            }
          })
        })
        return option;
      },
      opens(val){
        let query = {}
        if (val) {
            val.forEach((item) => {
                query[item.name]
            })
        }
        console.log(val,'nfjknkjnknkn')
        let url = http.ipAddress + 'api/erp_bill_flow_team/getPageData'
        let params = {
            page: this.$refs.table ? this.$refs.table.paginations.page : 1,
            rows: this.$refs.table ? this.$refs.table.paginations.rows : 30,
            sort: "Id",
            order: 'desc',
            wheres: "[]"
        }
        axios.post(url, params)
        .then(response => {
            console.log(params,'99');
            this.$refs.table.rowData = response.data.rows
            this.$refs.table.paginations.total = response.data.total
            // resolve(response.data);
        }).catch((error) => {
            this.$message.error(error);
        })
      },
      getStartDate(dates) {
        var dd = new Date();
        var n = dates || 0;
        dd.setDate(dd.getDate() + n);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1;
        var d = dd.getDate()-1;
        m = m < 10 ? "0" + m : m;
        d = d < 10 ? "0" + d : d;
        var day = y + "-" + m + "-" + d;
        return day;
      },
      getEndDate(dates) {
        var dd = new Date();
        var n = dates || 0;
        dd.setDate(dd.getDate() + n);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1;
        var d = dd.getDate()-1;
        m = m < 10 ? "0" + m : m;
        d = d < 10 ? "0" + d : d;
        var day = y + "-" + m + "-" + d;
        return day;
      },
    }
  };
  export default extension;
  